﻿using httpclient;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LabTimmer.Core
{
    internal class WriteLogs
    {
        private object obj1 = new object();
        private object obj2 = new object();
        private HttpPostToServer _httpPost;
        public void WriteDateTOLogs(string start, string stop)
        {
            string FILE_NAME = Environment.GetEnvironmentVariable("windir") + "\\YankDateLog.log";
            StreamWriter strw;
            if (File.Exists(FILE_NAME))
            {
                strw = File.AppendText(FILE_NAME);
            }
            else
            {
                strw = File.CreateText(FILE_NAME);
            }
            strw.WriteLine(start + "#" + stop);
            strw.Flush();
            strw.Close();
            GC.Collect();
        }

        static public void WriteErroTOLogs(string erre)
        {
            Boolean FLAG = true;
            string FILE_NAME = Application.StartupPath + "\\TimerLogs.log";
            StreamWriter strw = null ;
            if (File.Exists(FILE_NAME))
            {
                try
                {
                     strw = File.AppendText(FILE_NAME);
                }
                catch
                {
                    FLAG = false;
                }
                
            }
            else
            {
               
                try
                {
                    strw = File.CreateText(FILE_NAME);
                }
                catch
                {
                    FLAG = false;
                }
            }
            if (FLAG)
            {
                strw.WriteLine(DateTime.Now.ToString() + " : " + erre);
                strw.Flush();
                strw.Close();
            }
            
        }
    }
}
